package com.dengbw.systemtransfer.service;

import com.dengbw.systemtransfer.mapper.CmmFunctionCofigMapper;
import com.dengbw.systemtransfer.model.function.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * @author dengbw
 * @date 2021/11/11 2:38 下午
 */
@Service
public class CmmFunctionConfigService {

    CmmFunctionCofigMapper cmmFunctionCofigMapper;

    @Autowired
    public CmmFunctionConfigService(CmmFunctionCofigMapper cmmFunctionCofigMapper) {
        this.cmmFunctionCofigMapper = cmmFunctionCofigMapper;
    }

    @Transactional(rollbackFor = Exception.class)
    public void saveFunctionConfig(String zhenCorpId, Long cunSubId, Map<String, String> core) {
        Task.zhenConfigTask(zhenCorpId, core)
                .forEach(c -> {
                    if (Boolean.TRUE.equals(c.getOnlyCun()))
                        cmmFunctionCofigMapper.save(c.getUserType(), c.getNhType(), c.getGbType(),
                                c.getIsCz(), c.getSubject(), c.getOutUrl(), c.getImages(), c.getIsMr(), zhenCorpId,
                                c.getDefaultImages(), c.getSortNo(), c.getExtFlag(), cunSubId, c.getIsDel());
                });
    }
}
